using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using WindowsGame1.Interface;
using WindowsGame1.Objects3D;
using WindowsGame1.Windows;

namespace WindowsGame1.GameMain
{
    public class Core : Game
    {
        public GraphicsDeviceManager Graphics;
        public SpriteBatch SpriteBatch;
        private Canvas _canvas;

        public Core()
        {
            Graphics = new GraphicsDeviceManager(this);
            IsMouseVisible = true;
            Content.RootDirectory = "Content";
            
        }

        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        protected override void LoadContent()
        {
            SpriteBatch = new SpriteBatch(GraphicsDevice);

            StaticGUi.LoadContent(Content);
            StaticGUi.g = this;
            StaticGUi.Width = Window.ClientBounds.Width;
            StaticGUi.Height = Window.ClientBounds.Height;
            new clsCube(GraphicsDevice, 0, 0, new Vector3(0, 0, 0), new Vector3(0, 0, 0)).LoadContent(Content);

            LoadMenu();
        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                Exit();

            Input.Update(gameTime);
            _canvas.Update(gameTime);

            StaticGUi.Update(gameTime);

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            SpriteBatch.Begin();

            _canvas.Render(SpriteBatch);

            StaticGUi.Render(SpriteBatch);

            SpriteBatch.End();  

            base.Draw(gameTime);
        }

        public void LoadMenu()
        {
            _canvas = new Menu(this);
            _canvas.LoadContent(Content);
        }

        public void LoadGame()
        {
            _canvas = new MainGame(this);
            _canvas.LoadContent(Content);
            StaticGUi.Time.StartGame();
        }

        public void LoadEndGame()
        {
            _canvas = new EndGame();
            _canvas.LoadContent(Content);
            StaticGUi.Time.FinishGame();
            StaticGUi.End.Visible(true);
        }
    }
}
